package proxy;

import testClass.Eat;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author :spj
 * @Date:2022/3/28
 * @description:
 */
public class Jdk {
    public Object getProxy(Object o){
        Object proxy = Proxy.newProxyInstance(o.getClass().getClassLoader(), o.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理前置");
                Object invoke = method.invoke(o, args);
                System.out.println("代理后置");
                return invoke;
            }
        });
        return proxy;
    }
}
